/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.card;

import deatax.RNG;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;

/**
 *
 * @author Pieman
 */
public class CardPile {

    private LinkedList<Card> pile;
    private ArrayList<Card> pool;

    public CardPile() {
        pile = new LinkedList<Card>();
        pool = new ArrayList<Card>();
    }

    public void addCard(Card c) {
        for (int i = 0; i < c.getFreq(); ++i) {
            pool.add(c);
        }
    }

    public void shuffle() {
        pile.clear();
        Collections.shuffle(pool, RNG.get());
        for (Card c : pool) {
            pile.push(c);
        }
    }
    
    public Card draw() {
        if (pile.isEmpty()) {
            shuffle();
        }
        return pile.pop();
    }
}
